package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.Constan;
import service.EmployeeAPI;
import service.implement.EmployeeDAO;
import model.Employee;

/**
 * Servlet implementation class doaddEmployee
 */
@WebServlet("/doaddEmployee")
public class doaddEmployee extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public doaddEmployee() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException  {
		// TODO Auto-generated method stub
		PrintWriter pw=response.getWriter();
		String name=request.getParameter("name");
		String username=request.getParameter("username");
		String email=request.getParameter("email");
		int id = java.sql.Types.NULL;
		Employee emp=new Employee(id,name,username,email);
		EmployeeDAO dao=new EmployeeDAO();
		if(dao.addEmployee(emp)==Constan.SER_STATUS_SUCSESS){
			RequestDispatcher rd = request.getRequestDispatcher("listEmployee.jsp");
			rd.forward(request, response);
		}
		else{
			RequestDispatcher rd = request.getRequestDispatcher("EmployeeForm.jsp");
			rd.forward(request, response);
		}
	}

}
